
//添加奇门

import React, { useState } from "react";
import CommonModal from '@/components/CommonModal';
import CommonLoading from '@/components/CommonLoading';
import { Input, Form, message } from 'antd';
import { layout1 } from '@/utils/config';
import { saveOfflineStore } from '@/services/common';
import { useNavigate } from 'react-router-dom'

export default ({ visible, handleVisible }) => {

  const [form] = Form.useForm();
  const [loading, setLoading] = useState(false);
	const navigate = useNavigate();
  const handleSubmit = async () => {
    setLoading(true);
    const { storeName, token } = form.getFieldsValue();
    const res = await saveOfflineStore({
      storeName,
      token,
      type: 13
    })
    setLoading(false);
    if (res.success) {
      message.success('添加成功！');
      navigate(0);
    }
  }

  const onOk = () => {
    form.validateFields().then(val => {
      handleSubmit();
    })
  }

  return (
    <CommonModal
      title='新增奇门授权'
      visible={visible}
      onCancel={() => handleVisible(false)}
      onOk={onOk}
      width='600px'
    >
      <Form
        {...layout1}
        form={form}
        name="add-offline-store"
      >
        <Form.Item
          name="storeName"
          label="ERP名称"
          rules={[
            { required: true, message: 'ERP名称未填写' }
          ]}
        >
          <Input placeholder="请输入ERP名称" />
        </Form.Item>

        <Form.Item
          name="token"
          label="AppKey"
        >
          <Input placeholder="请输入AppKey" />
        </Form.Item>

      </Form>
      <CommonLoading loading={loading} />
    </CommonModal>
  );
};